﻿using System;
using System.Activities;
using Reactor.Workflow.Extensions;

namespace Reactor.Workflow.Activities
{
    public class PersistProperty<T> : CodeActivity
    {
        [RequiredArgument]
        public InArgument<string> PropertyName { get; set; }

        [RequiredArgument]
        public InArgument<T> Value { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            var ext = context.GetExtension<PersistedPropertiesExtension>();
            if(ext == null) throw new InvalidOperationException("No PersistedPropertiesExtension found.");

            ext.PromoteProperty(context.WorkflowInstanceId, context.GetValue(PropertyName), context.GetValue(Value));
        }
    }
}
